﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class MasterCarInsurance : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LiteralControl newln = new LiteralControl(Environment.NewLine);
        HtmlMeta language = new HtmlMeta();
        language.Name = "content-language";
        language.Content = Resources.Homepage.PageContent;

        //HtmlMeta keywords = new HtmlMeta();
        //keywords.Name = "keywords";
        //keywords.Content = Resources.Homepage.PageKeywords;

        //HtmlMeta description = new HtmlMeta();
        //description.Name = "description";
        //description.Content = Resources.Homepage.PageDescription;

        Page.Header.Controls.AddAt(10, new LiteralControl(Environment.NewLine));
        Page.Header.Controls.AddAt(11, language);

        //Page.Header.Controls.AddAt(12, new LiteralControl(Environment.NewLine));
        //Page.Header.Controls.AddAt(13, keywords);
        //Page.Header.Controls.AddAt(14, new LiteralControl(Environment.NewLine));
        //Page.Header.Controls.AddAt(15, description);

        //Page.Header.Controls.Add(keywords);
        //Page.Header.Controls.Add(new LiteralControl(Environment.NewLine));
        //Page.Header.Controls.Add(description);
        //Page.Header.Controls.Add(new LiteralControl(Environment.NewLine));


        HtmlLink css = new HtmlLink();
        css.Href = Resources.General.CssUrl;
        css.Attributes["rel"] = "stylesheet";
        css.Attributes["type"] = "text/css";
        css.Attributes["media"] = "all";
        Page.Header.Controls.Add(css);

        HtmlLink cssButton = new HtmlLink();
        cssButton.Href = Resources.General.CssButtonUrl;
        cssButton.Attributes["rel"] = "stylesheet";
        cssButton.Attributes["type"] = "text/css";
        cssButton.Attributes["media"] = "all";
        Page.Header.Controls.Add(cssButton);

        HtmlLink cssForm = new HtmlLink();
        cssForm.Href = Resources.General.CssFormResultUrl;
        cssForm.Attributes["rel"] = "stylesheet";
        cssForm.Attributes["type"] = "text/css";
        cssForm.Attributes["media"] = "all";
        Page.Header.Controls.Add(cssForm);

        Page.Header.Controls.Add(css);

        //hplAboutUs.NavigateUrl = CE.Global.General.GetUrl("~/aboutus/aboutus.aspx", Page);

        string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("TH.IsCXLive");
        if (_strCXLive == "0")
        {
            if (Session[CE.Global.General.Guest] == null)
            {
                Response.Redirect("~/Default.aspx");
            }
            else if (Session[CE.Global.General.Guest].ToString() == "Provider")
            {
                if (Session[CE.Global.General.UserId] == null)
                {
                    Response.Redirect("~/provider/providersecurelogin.aspx");
                }
                else if (Session[CE.Global.General.UserTypeId] != null)
                {
                    if (Convert.ToInt32(Session[CE.Global.General.UserTypeId].ToString()) == Convert.ToInt32(CE.Global.CEUserType.Provider))
                    {
                        Response.Redirect("~/car-insurance/car-and-policy-details.aspx");
                    }
                    else
                    {
                        Response.Redirect("~/provider/providersecurelogin.aspx");
                    }
                }
                else
                {
                    Response.Redirect("~/provider/providersecurelogin.aspx");
                }
            }

        }
        else
        {
            //if (Session[CE.Global.General.Guest] == null)
            //{
            //    Response.Redirect("www.comparexpress.co.th");
            //}
        }


        if (Session[CE.Global.General.UserId] != null)
        {
            CE.Global.General.CreateUpdateUserLoginCached(Page);
            imgLogin.ImageUrl = "/images/button/signout_lrg.gif";
            imgLogin.Visible = false;
            divUserName.Visible = true;
            string _userName = Session[CE.Global.General.UserName].ToString();
            if (_userName.Length > 20)
            {
                lblUserName.Text = _userName.Substring(0, 20) + "..";
            }
            else
            {
                lblUserName.Text = _userName;
            }
            hplLogin.ToolTip = _userName;
            //hplLogin.NavigateUrl = "~/user/logout.aspx";
            hplLogin.Font.Underline = false;
        }

        //Session[CE.Global.General.Guest] != null ||
        //No session expire alert after logout
        if (Session[CE.Global.General.UserId] != null ||
            Session[CE.Global.General.CarId] != null)
        {
            //CE.Global.General.CreateUpdateUserLoginCached(Page);
            //Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "JS_AjaxSessionTimer", "../includes/AjaxSessionTimer.js");
            Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "JS_AjaxSessionTimer", Resources.General.AJAXSessionTimerUrl);
            Page.ClientScript.RegisterClientScriptInclude(this.GetType(), "JS_Net", "/includes/net.js");
        }
        if (!IsPostBack)
        {
            hplHome.NavigateUrl = CE.Global.General.GetUrl("/home.aspx", Page);
            
            hplClass.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/car-details.aspx", Page);
            hplCTPL.NavigateUrl = CE.Global.General.GetUrl("/cmi/cmi-main.aspx", Page);
            //hplClass1.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/class-1.aspx", Page);
            //hplClass2plus.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/class-2plus.aspx", Page);
            //hplClass3plus.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/class-3plus.aspx", Page);
            //hplClass3.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/class-3.aspx", Page);
            //hplFooterClass1.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/class-1.aspx", Page);
            //hplFooterClass2plus.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/class-2plus.aspx", Page);
            //hplFooterClass3plus.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/class-3plus.aspx", Page);
            //hplFooterClass3.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/class-3.aspx", Page);

            //hplClass1.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/quote-results.aspx", Page); //class=1
            //hplClass2plus.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/quote-results.aspx", Page); //class=2P
            //hplClass3plus.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/quote-results.aspx", Page); //class=3P
            //hplClass3.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/quote-results.aspx", Page); //class=3
            //hplFooterClass1.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/quote-results.aspx", Page); //class=1
            //hplFooterClass2plus.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/quote-results.aspx", Page); //class=2P
            //hplFooterClass3plus.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/quote-results.aspx", Page); //class=3P
            //hplFooterClass3.NavigateUrl = CE.Global.General.GetUrl("/car-insurance/quote-results.aspx", Page); //class=3

            //hplFooterCTPL.NavigateUrl = CE.Global.General.GetUrl("/cmi/cmi-main.aspx", Page);

            hplFooterHome.NavigateUrl = CE.Global.General.GetUrl("/home.aspx", Page);
            hplAboutUs.NavigateUrl = CE.Global.General.GetUrl("/aboutus/", Page);
            hplFAQ.NavigateUrl = CE.Global.General.GetUrl("/faq/", Page);
            hplPrivacy.NavigateUrl = CE.Global.General.GetUrl("/privacy/", Page);
            hplTerms.NavigateUrl = CE.Global.General.GetUrl("/terms/", Page);
            hplSitemap.NavigateUrl = CE.Global.General.GetUrl("/sitemap/", Page);
            hplContactUs.NavigateUrl = CE.Global.General.GetUrl("/contactus/", Page);
            hplNews.NavigateUrl = CE.Global.General.GetUrl("/news/news.aspx", Page);
            hplMedia.NavigateUrl = CE.Global.General.GetUrl("/news/media.aspx", Page);
        }
    }

    protected void btnSetClassSession_Click(object sender, EventArgs e)
    {
        Session["CLASSTYPE"] = hidClassSession.Value;
        string urlClass = CE.Global.General.GetUrl("/car-insurance/quote-results.aspx", Page);
        Response.Redirect(urlClass);
    }
}
